#include "sdk.h"
#include "genericmultilinenotesdlg.h"

bool xml_File_lock;

BEGIN_EVENT_TABLE( GenericMultiLineNotesDlg, wxScrollingDialog )

END_EVENT_TABLE()

GenericMultiLineNotesDlg::GenericMultiLineNotesDlg( wxWindow* parent, const wxString& caption, const wxString& notes, bool readOnly ) : m_Notes( notes ), m_ReadOnly( readOnly ) {
  wxXmlResource* xml_res = wxXmlResource::Get();
  wxString resPath = ConfigManager::GetDataFolder() + _T( "/generic_multiline_notes.xrc" );
  if( !xml_res->Load( resPath ) )  {
    xml_File_lock = false;
    Manager::Get()->GetLogManager()->LogInf( F( _T( "文件丢失: %s " ), resPath.wx_str() ) );
    return;
  }
  if( !xml_res->LoadObject( this, parent, _T( "dlgGenericMultiLineNotes" ), _T( "wxScrollingDialog" ) ) ) {
    xml_File_lock = false;
    Manager::Get()->GetLogManager()->LogInf( _T( "资源丢失" ) );
    return;
  }
  xml_File_lock = true;
  SetTitle( caption );
  wxTextCtrl *notesCtrl = XRCCTRL( *this, "txtNotes", wxTextCtrl );
  notesCtrl->SetValue( m_Notes );
  if( m_ReadOnly ) {
    notesCtrl->SetEditable( false );
    if( wxWindow* win = FindWindowById( wxID_CANCEL, this ) ) {
      win->Enable( false );
    }
    XRCCTRL( *this, "wxID_OK", wxButton )->SetDefault();
  } else {
    notesCtrl->SetFocus();
  }
}

GenericMultiLineNotesDlg::~GenericMultiLineNotesDlg() {
}

void GenericMultiLineNotesDlg::EndModal( int retCode ) {
  if( retCode == wxID_OK && !m_ReadOnly ) {
    m_Notes = XRCCTRL( *this, "txtNotes", wxTextCtrl )->GetValue();
  }
  wxScrollingDialog::EndModal( retCode );
}
